﻿using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NewBee.Core.Data.Model
{
    /// <summary>
    /// 分页参数
    /// </summary>
    public class PageParam : BaseModel
    {
        IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();

        /// <summary>
        /// 构造函数
        /// </summary>
        public PageParam()
        {
            selectColumn = " * ";
            rows = 20;
            page = 1;
            orderParam = new Dictionary<string, bool>();
            timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_rows">每页行数</param>
        /// <param name="_page">当前页码</param>
        public PageParam(int _rows, int _page) : this()
        {
            rows = _rows;
            page = _page;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_page">当前页码</param>
        public PageParam(int _page) : this()
        {
            page = _page;
        }

        /// <summary>
        /// select显示列
        /// </summary>
        public string selectColumn { get; private set; }

        /// <summary>
        /// 设置Select显示列
        /// </summary>
        /// <param name="selectColumn"></param>
        /// <returns></returns>
        public PageParam Select(string _selectColumn)
        {
            selectColumn = _selectColumn;
            return this;
        }

        /// <summary>
        /// where条件
        /// </summary>
        public string whereSql { get; private set; }

        /// <summary>
        ///  where条件
        /// </summary>
        /// <param name="whereSql"></param>
        /// <returns></returns>
        public PageParam Where(string _whereSql)
        {
            whereSql = _whereSql;
            return this;
        }

        /// <summary>
        /// where参数
        /// </summary>
        public object param { get; set; }

        /// <summary>
        /// 每页显示条数
        /// </summary>
        public int rows { get; private set; }

        /// <summary>
        /// 当前页
        /// </summary>
        public int page { get; private set; }

        /// <summary>
        /// 排序信息：字段名称，是否正序
        /// </summary>
        public IDictionary<string, bool> orderParam { get; private set; }

        /// <summary>
        /// 其它值
        /// </summary>
        public string Data { get; set; }

        /// <summary>
        /// 设置排序
        /// </summary>
        /// <param name="orderColumn">查询字段</param>
        /// <param name="isAsc">是否正序</param>
        /// <returns></returns>
        public PageParam Order(string orderColumn, bool isAsc)
        {
            orderParam.Add(orderColumn, isAsc);
            return this;
        }
    }
}
